package com.lg.customrxjava.generics;

import com.lg.customrxjava.custombean.Human;
import com.lg.customrxjava.custombean.PracticeTeacher;
import com.lg.customrxjava.custombean.Teacher;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class GenericsTest {

    public static void main(String[] args) {
        List<String> strList = new ArrayList<String>();
        List<Integer> intList = new ArrayList<Integer>();
        List<Number> numList = new ArrayList<Number>();

        intList.add(123);
        strList.add("abc");

        getResult(intList);
        getResult(strList);

        //
        numberPlus(intList);
       // numberPlus(strList);

        List<Teacher> tList = new ArrayList<Teacher>();
        List<PracticeTeacher> ptList = new ArrayList<PracticeTeacher>();
        List<Human> hList = new ArrayList<Human>();
        ptList.add(new PracticeTeacher());

        addMeetting(tList);
        addMeetting(hList);

        //addMeetting(ptList);


        Collections.copy(numList,intList);
        //Collections.copy(intList,numList);

    }

    //任意
    static void getResult(List<?> list){
        System.out.println("data :" + list.get(0));
    }

    //限制只传入int类型进行计算，限制上限类型，可读
    static void numberPlus(List<? extends  Number> list){
        Number b= 123;
        //list.add(0,b);
        int a = (Integer) list.get(0);
        a=a+a;
        System.out.println("numberPlus :" + a);
    }



    static void addMeetting(List<? super Teacher > t){
        Teacher t2 =new Teacher();
        t.add(2,t2);
    }

    static void addMeetting2(List<? extends Teacher > t){
        Teacher t2 =new Teacher();
        //t.add(2,t2);
        t.get(0);
    }

    static void addMeetting(List<? super Human  > t,List<? extends PracticeTeacher > t2){
        PracticeTeacher pt1 =new PracticeTeacher();
        PracticeTeacher pt2 =new PracticeTeacher();

        t.add(0,pt1);
        t.add(2,pt2);
        t.addAll(t2);
       //t2.addAll(t);

    }


}
